package com.example.fw;

import org.openqa.selenium.By;

public class NavigationHelper extends WebDriverHelperBase {
	
	public static boolean CLICK_LINK = true;
	public static boolean GET_PAGE = false;
	
	public NavigationHelper(ApplicationManager manager) {
		super(manager);
	}

	public void mainPage(boolean typeTransition) {
		if(! onMainPage() && typeTransition == CLICK_LINK){			
			click(By.linkText("home"));
		} else {
			driver.get(manager.baseUrl);
		}		
	}

	private boolean onMainPage() {
		return driver.findElements(By.id("maintable")).size() > 0;			
	}

	public void groupsPage() {
		if(! onGroupsPage()){
			click(By.linkText("groups"));
		}
		
	}
	
	private boolean onGroupsPage() {
		if(driver.getCurrentUrl().contains("/group.php")
				&& driver.findElements(By.name("new")).size() > 0){
			return true;
			
		} else {
			return false;
		}		
	}

	public void contactCreationPage() {
		if(! onAddContactPage()){
			
		}
		click(By.linkText("add new"));
	}

	private boolean onAddContactPage() {
		if(driver.getCurrentUrl().contains("/edit.php")
				&& driver.findElement(By.tagName("h1")).equals("Edit / add address book entry")){
			return true;
			
		} else {
			return false;
		}		
	}
	
	public void printPhonesPage(){
		if(! onPrintPhonesPage()){
			click(By.linkText("print phones"));
		}
	}

	private boolean onPrintPhonesPage() {
		if(driver.getCurrentUrl().contains("/view.php?all&print&phones")
				&& driver.findElement(By.tagName("h1")).equals("Address book")){
			return true;
			
		} else {
			return false;
		}		
	}
}
